﻿using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;
using SellAndBuy.Application.Query.DTOs;

namespace SellAndBuy.Infrastructure.Data.Query.Mappings
{
    public class ItemCategoryDTOMap : ClassMapping<ItemCategoryDTO>
    {
        public ItemCategoryDTOMap()
        {
            Lazy(false);
            Table("ItemCategory");
            Property(x => x.Name, map => { map.Length(150); map.NotNullable(true); });
            Bag(x => x.AvailableConditions,
                collectionMapping =>
                {
                    collectionMapping.Access(Accessor.NoSetter);
                    collectionMapping.Cascade(Cascade.All);
                    collectionMapping.Key(k => k.Column("ItemConditionID"));
                    collectionMapping.Lazy(CollectionLazy.NoLazy);
                },
                mapping => mapping.Component(ItemConditionDTOMap.MappingElements()));
        }    
    }
}